<?php

class HomeController extends BaseController {

	public function showLogin()
	{
        if(Auth::check()) {
            return Redirect::route('dashboard');
        }else{
            return View::make('layout.login');
        }
	}

    public function showDashboard()
    {                        
        $count_lokasis      = Lokasi::active()->count();
        $count_penduduks    = Penduduk::active()->count();        
        $count_kipems       = Kipem::active()->count();
        $count_tamus        = Tamu::active()->count();     
        $count_kipems_akan  = Kipem::where('is_active','=','1')->where('tanggal_akhir', '<=', DB::raw('DATE_ADD(NOW(),INTERVAL 5 DAY)'))->where('tanggal_akhir', '>', DB::raw('DATE(NOW())'))->count();   
        $count_kipems_habis = Kipem::where('is_active','=','1')->where('tanggal_akhir', '=', DB::raw('DATE(NOW())'))->count();
        $count_kipems_sudah = Kipem::where('is_active','=','1')->where('tanggal_akhir', '<', DB::raw('DATE(NOW())'))->count();

        return View::make('dashboard.index')
            ->with(compact('count_penduduks'))
            ->with(compact('count_lokasis'))
            ->with(compact('count_kipems'))
            ->with(compact('count_tamus'))
            ->with(compact('count_kipems_akan'))
            ->with(compact('count_kipems_habis'))
            ->with(compact('count_kipems_sudah'));
    }
}
